package Infinite::Sequence::Combined;
use base qw{Infinite::Sequence};

sub new {
    my( $class, $A, $B, $op, $swapped ) = @_;
    my $this = $class->SUPER::new();
	$this->{A} 			= $A;
	$this->{B} 			= $B;
	$this->{op} 		= $op;
	$this->{swapped}	= $swapped ? 1 : 0;
	$this->{sequence}	= ref($B) ?
							( $B->isa(q{Infinite::Sequence}) ? 1 : 0 ) : 0;
	$this
}

sub increment {
    my $this = shift;
    my $ret;
    
    my $a = $this->{A}->increment();
    my $b = $this->{sequence} ? $this->{B}->increment() : $this->{B};
	
	if( $this->{swapped} ) {
		my $temp = $a;
		$a = $b;
		$b = $temp;
	}

    eval q{ $ret = $a } . $this->{op} . q{ $b };
    die $@ if $@;
    $ret;
}

1;
